//
//  RandomSelectNumView.m
//  PlayBall
//
//  Created by Edward Zhang on 12-5-15.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddRandomSelectNumView.h"

@implementation JddRandomSelectNumView

@synthesize typelabel;
@synthesize delegate;
@synthesize type;
@synthesize multipleTextField;
GET_INSTANCE_VIEW_IMPLEMENT(JddRandomSelectNumView)

-(IBAction)cancelButtonClicked:(id)sender{
    [self dismissAnimated:YES];
}

-(IBAction)okButtonClicked:(id)sender{
    [self dismissAnimated:YES];
    if (type==1) {
            [delegate performSelector:@selector(RandomSelectNumViewClickedButtonAtIndex:multiple:) withObject:[NSNumber numberWithInt:1] withObject:[NSNumber numberWithInt:[multipleTextField.text intValue]]];
    }else if(type == 2){
            [delegate performSelector:@selector(selectRedBall:multiple:) withObject:[NSNumber numberWithInt:1] withObject:[NSNumber numberWithInt:[multipleTextField.text intValue]]];
    }else if(type == 3){
        [delegate performSelector:@selector(selectBlueBall:multiple:) withObject:[NSNumber numberWithInt:1] withObject:[NSNumber numberWithInt:[multipleTextField.text intValue]]];
    }else if(type == 4){
        [delegate performSelector:@selector(selectHeadBall:multiple:) withObject:[NSNumber numberWithInt:1] withObject:[NSNumber numberWithInt:[multipleTextField.text intValue]]];
    }else if(type == 5){
        [delegate performSelector:@selector(selectBackBall:multiple:) withObject:[NSNumber numberWithInt:1] withObject:[NSNumber numberWithInt:[multipleTextField.text intValue]]];
    }
}

-(IBAction)minusButtonClicked:(id)sender{
    NSInteger multiple = [multipleTextField.text intValue];
    if (type==1) {
        if (multiple-- < 2) {
            multipleTextField.text = @"1";
            return;
        }
    }else if(type == 2) {
        if (multiple-- < 7) {
            multipleTextField.text = @"6";
            return;
        }
    }else if(type == 3) {
        if (multiple-- < 2) {
            multipleTextField.text = @"1";
            return;
        }
    }else if(type == 4) {
        if (multiple-- < 6) {
            multipleTextField.text = @"5";
            return;
        }
    }else if(type == 5) {
        if (multiple-- < 3) {
            multipleTextField.text = @"2";
            return;
        }
    }

    
    multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
}

-(IBAction)plusButtonClicked:(id)sender{
    NSInteger multiple = [multipleTextField.text intValue];
    if (type == 2) {
        if (multiple++ >19) {
            multipleTextField.text = @"20";
            return;
        }else {
            multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
        }
    }else if(type == 3) {
        if (multiple++ > 15) {
            multipleTextField.text = @"16";
            return;
        }else {
            multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
        }
    }else if(type == 4) {
        if (multiple++ > 17) {
            multipleTextField.text = @"18";
            return;
        }else {
            multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
        }
    }else if(type == 5) {
        if (multiple++ > 11) {
            multipleTextField.text = @"12";
            return;
        }else {
            multipleTextField.text = [NSString stringWithFormat:@"%d", multiple];
        }
    }else {
        multipleTextField.text = [NSString stringWithFormat:@"%d", ++multiple];        
    }
    
}

- (void)loadContentView{
    NSArray *viewArray = [[NSBundle mainBundle] loadNibNamed:@"JddRandomSelectNumView" owner:self options:nil];

    _contentView = [viewArray objectAtIndex:0];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return NO;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
